package com.zzw.httpclient;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * Created by ZZW on 2016/4/1.
 */
public class StreamUtil {

    public static String readInputStream(InputStream is){
        ByteArrayOutputStream bai = new ByteArrayOutputStream();
        int len = 0 ;
        byte[] buffer = new byte[1024];
        try{
            while((len = is.read(buffer)) != -1){
                bai.write(buffer,0,len);
            }
            is.close();
            bai.close();
            byte[] result = bai.toByteArray();
            return new String(result);
        }catch (Exception e){
            e.printStackTrace();
            return "获取失败";
        }
    }
}
